//
//  UIView+WLCore.m
//  SeaWorld
//
//  Created by 专注 on 2017/9/8.
//  Copyright © 2017年 Rice. All rights reserved.
//

#import "UIView+WLCore.h"

@implementation UIView (WLCore)
#pragma mark - 设置部分圆角
/**
 *  设置部分圆角(绝对布局)
 *
 *  @param corners 需要设置为圆角的角 UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight | UIRectCornerAllCorners
 *  @param radii   需要设置的圆角大小 例如 CGSizeMake(20.0f, 20.0f)
 */
- (void)wl_addRoundedCorners:(UIRectCorner)corners
                withRadii:(CGSize)radii {
    
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radii];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    
    self.layer.mask = shape;
}

/**
 *  设置部分圆角(相对布局)
 *
 *  @param corners 需要设置为圆角的角 UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight | UIRectCornerAllCorners
 *  @param radii   需要设置的圆角大小 例如 CGSizeMake(20.0f, 20.0f)
 *  @param rect    需要设置的圆角view的rect
 */
- (void)wl_addRoundedCorners:(UIRectCorner)corners
                withRadii:(CGSize)radii
                 viewRect:(CGRect)rect {
    
    UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radii];
    CAShapeLayer* shape = [[CAShapeLayer alloc] init];
    [shape setPath:rounded.CGPath];
    
    self.layer.mask = shape;
}


-(void)wl_cornerRadius{
    self.layer.cornerRadius  = 5;
    self.clipsToBounds = YES;
}
/**
 试图圆形
 */
-(void)wl_cornerRound{
    self.layer.cornerRadius  = self.frame.size.width/2;
    self.clipsToBounds = YES;
}
-(void)wl_cornerRadius:(CGFloat)x{
    self.layer.cornerRadius  = x;
    self.clipsToBounds = YES;
}
-(void)wl_borderWidth:(CGFloat)w borderColor:(UIColor *)color{
    self.layer.borderWidth = w;
    self.layer.borderColor = [color CGColor];
}
-(void)wl_cornerRadius:(CGFloat)x borderWidth:(CGFloat)w borderColor:(UIColor *)color{
    self.layer.borderWidth = w;
    self.layer.borderColor = [color CGColor];
    self.layer.cornerRadius  = x;
    self.clipsToBounds = YES;
}

@end
